/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.is.city.search;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.util.Properties;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import net.miginfocom.swing.MigLayout;

/**
 *
 * @author oleg
 */
public class JSearchFrame extends JFrame{
    SearchSettingsController controller;
    JTextField field;
    JTextField field2;
    JTextField field3;
    JFrame frame;

    public JSearchFrame(final SearchSettingsController controller) throws HeadlessException {
        this.controller = controller;
        JPanel panel = new JPanel(new MigLayout());
        JLabel jLabel = new JLabel("Адрес БД");
        field = new JTextField(controller.getJdbc_url());
        field.setPreferredSize(new Dimension(300, 20));
        panel.add(jLabel);
        panel.add(field, "wrap");

        JLabel jLabel2 = new JLabel("имя");
        field2 = new JTextField(controller.getProperties().getProperty("user"));
        field2.setPreferredSize(new Dimension(300, 20));
        panel.add(jLabel2);
        panel.add(field2, "wrap");

        JLabel jLabel3 = new JLabel("пароль");
        field3 = new JTextField(controller.getProperties().getProperty("password"));
        field3.setPreferredSize(new Dimension(300, 20));
        panel.add(jLabel3);
        panel.add(field3, "wrap");
        frame=this;
        JButton okBtn = new JButton(new AbstractAction("OK") {

            @Override
            public void actionPerformed(ActionEvent e) {
                controller.setJdbc_url(field.getText());
                Properties properties = controller.getProperties();
                properties.setProperty("user", field2.getText());
                properties.setProperty("password", field3.getText());
                controller.setProps(properties);
                frame.setVisible(false);
                controller.save();
            }
        });
        
        panel.add(okBtn);
        add(panel);
        setSize(new Dimension(400, 170));
    }
    
}
